<?php

class IndexController extends Controller
{
	public function actionIndex()
	{
        // 展现标签
        $tag = new Tags();
        $criteria = new CDbCriteria();
        $criteria->select = 'id, tag_name';
        $criteria->limit = '15';
        $tagsData = $tag->findAll($criteria);

        // 展现最新的和置顶文章
        $article = new Article();
        $criteria = new CDbCriteria();
        $criteria->select = 'id,article_title, article_summary, article_thumbnail, article_nav, article_is_top, article_date, article_admin';
        $criteria->limit = '5';
        $criteria->order = 'article_is_top desc,article_date desc';

        $articleList = $article->findAll($criteria);

        $nav = new Nav();
        foreach($articleList as $key=>$val)
        {
            $temp = $nav->findByAttributes(array('id'=>$val->article_nav), array('select'=>'nav_name'));
            $val->article_nav = $temp->nav_name;
        }

		// 获取随机图文
		$criteria = new CDbCriteria();
		$criteria->select = 'id,article_title, article_summary, article_thumbnail, article_date';
		$criteria->limit = '4';
		$criteria->order = 'rand()';

		$randList = $article->findAll($criteria);

		foreach($randList as $key=>$val)
		{
			$val->article_summary = BlogTool::cutText($val->article_summary, 13);
			$val->article_title = BlogTool::cutText($val->article_title, 13);
		}

        $this->render('index', array(
            'tagsData'=>$tagsData,
            'articleList'=>$articleList,
			'randList'=>$randList,
        ));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}